package com.zzsy.carosshopprojects.activitys.home.mainpage.main;

import android.content.DialogInterface;
import android.graphics.Color;
import android.view.KeyEvent;

import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.base.BaseActivity;

import androidx.appcompat.app.AlertDialog;
import me.yokeyword.fragmentation.anim.FragmentAnimator;

/**
 * 项目主页
 */
public class HomePageAc extends BaseActivity {
    @Override
    protected int bindLayout() {
        return R.layout.ac_common;
    }

    @Override
    protected void initView() {
        loadRootFragment(R.id.fl_container, HomePageFragment.newInstance());
        //全局改变Fragment的动画
        setFragmentAnimator(new FragmentAnimator());
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void loadMethod() {

    }

    /**
     * 返回键隐藏到后台
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            quitDialog();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /*退出对话框*/
    public void quitDialog() {
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(getResources().getString(R.string.tips))
                .setMessage(getResources().getString(R.string.exitSystem))
                .setPositiveButton(getResources().getString(R.string.sure), (dialog1, which) -> {
//                    Intent intent = new Intent(Intent.ACTION_MAIN);
//                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    intent.addCategory(Intent.CATEGORY_HOME);
//                    startActivity(intent);
                    finish();
//                    android.os.Process.killProcess(android.os.Process.myPid());
//                     System.exit(0);
                })
                .setNegativeButton(getResources().getString(R.string.cancel), (dialog12, which) -> {
                });
        AlertDialog dialog_dialog = dialog.create();
        dialog_dialog.show();
        dialog_dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#ff6900"));
        dialog_dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#000000"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // SunmiPrintHelper.getInstance().deInitSunmiPrinterService(getApplicationContext());
    }
}
